package com.versita.utils;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.apache.log4j.Logger;

public class ShadowEntityManager {
    static Logger logger = Logger.getLogger(ShadowEntityManager.class);
    static EntityManagerFactory emf = getEntityManagerFactory();

    public static EntityManagerFactory getEntityManagerFactory() {
        if (emf == null) {
            emf = Persistence.createEntityManagerFactory("shadow-life-jpa");
            return emf;
        } else {
            return emf;
        }
    }

    public static EntityManager getEntityManager() {
        if (emf == null) {
            logger.error("EntityManagerFactory is null.");
            return null;
        } else {
            return emf.createEntityManager();
        }
    }
}
